package com.credithc.signature.core;

import cfca.seal.bean.SealUserInfo;
import cfca.seal.bean.SignLocation;
import cfca.seal.util.FileUtil;
import cfca.seal.util.StrategyUtil;
import cfca.seal.util.StringUtil;
import cfca.seal.ws.SealClient;
import com.credithc.signature.common.constant.CoreConstant;
import com.credithc.signature.common.constant.SealConstant;
import com.credithc.signature.common.utils.ErrorCodeHelper;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.nio.charset.StandardCharsets;

@Slf4j
public class MySealAutoPdfTest2 {

    //自动化盖章--坐标盖章
    public static void main(String[] args) throws Exception {
        String host = "http://10.150.27.227:8091/Seal";
        SealClient client = new SealClient(host);

        String sealCode = "OFFICE_40707802";
        String sealPassword = "5852763736";
        String sealPerson = "恒昌利通";
        String sealLocation = "_华_夏_国_鼎_";
        String sealReason = "测试签章";
        String businessCode = CoreConstant.BUSINESS_CODE;
        String businessCodeStyle = "font-size\\:10;x-ratio\\:1;y-ratio\\:1;color\\:FF0000";
        String page = "1,2,3";// 支持（1）单页，（1,2,3,4）多页,（1-3）区间，（0）所有页
        int lX = 200;
        int lY = 500;

        String path = "D:\\test.pdf";
        byte[] pdf = FileUtil.getBytesFromFile(new File(path));
        SealUserInfo sealUserInfo = new SealUserInfo(sealPerson, sealLocation, sealReason);
        SignLocation signLocation = new SignLocation(page, lX, lY);
        String sealStrategyXML = StrategyUtil.createSealStrategyXml(sealCode, sealPassword, businessCode, businessCodeStyle, sealUserInfo, signLocation);


        byte[] resultData = client.sealAutoPdf(pdf, sealStrategyXML);
        if (StringUtil.checkResultDataValid(resultData)) {
            String savePath = "D:\\signature.pdf";
            FileUtil.wirteDataToFile(savePath, resultData);
            System.out.println("SealAutoPdfTest(Webservice) ok and save data to \"" + savePath + "\'");
        } else {
            System.out.println("SealAutoPdfTest(Webservice) wrong:" + new String(resultData));
        }

    }

}
